package com.naiterui.ehp.bs.b2c.order.repository;

import com.naiterui.common.repository.core.BaseJpaRepository;
import com.naiterui.ehp.bs.b2c.order.entity.Order;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

/**
 * 订单
 *
 * @date 2017年09月09日
 * @since 1.0.0
 */
@Repository
public interface IOrderRepository extends BaseJpaRepository<Order, Long> {

    Order findByOrderSn(String orderSn);

    List<Order> findByIdIn(Set<Long> orderIds);

    List<Order> findByIdInAndWarehouseId(Set<Long> orderIds, Long warehouseId);

    /**
     * 根据用户和订单ID查询订单详情
     */
    Order findByIdAndUserId(Long id, Long userId);

    /**
     * 根据用户分页获取订单列表
     */
    Page<Order> findAllByUserId(Long userId, Pageable pageable);

    List<Order> findByOrderStatusAndWarehouseIdNotNull(Integer orderStatus);

    List<Order> findByOrderStatusInAndWarehouseIdNull(Set<Integer> orderStatus);

    List<Order> findByOrderStatus(Integer orderStatus);

    List<Order> findByOrderStatusAndChangedAtBefore(Integer orderStatus, Date createdAt);

    Page<Order> findByUserIdAndOrderStatusIn(Long userId, Set<Integer> orderStatus, Pageable pageable);

    List<Order> findByOrderStatusNotIn(Collection<Integer> status);

    Integer countByUserIdAndOrderStatus(Long userId, Integer orderStatus);

    Integer countByUserIdAndOrderStatusIn(Long userId, Collection<Integer> orderStatus);
}
